<head>
@extends('layouts.admin_common') @section('content')

{{Breadcrumbs::render('admin.set_add') }} @if(app('env')=='production')

<link rel="stylesheet" href="{{ secure_asset('/css/sale.css') }}">
<!-- <script src="{{ secure_asset('/js/jquery-3.3.1.min.js') }}"></script> -->
<script src="{{ secure_asset('/js/set.js') }}"></script>
@else
<link rel="stylesheet" href="{{ asset('/css/sale.css') }}">
<!-- <script src="{{ asset('/js/jquery-3.3.1.min.js') }}"></script> -->
<script src="{{ asset('/js/set.js') }}"></script>
@endif
<script>
$(document).ready(function() {
	$("#goodCodeId").quickTip("setjson",{},function(){
	});
});
</script>
</head>
<script src="{{ asset('laydate/laydate.js') }}"></script>
<script>

laydate.render({
	  elem: '#start_date'
	  ,lang: 'en'
	  ,type: 'datetime'
	});
laydate.render({
	  elem: '#end_date'
	  ,lang: 'en'
	  ,type: 'datetime'
	});
</script>
<script>
    function addRow(obj){

    	var setgood = $("#addTable").find("input[class^=suggestion]").length;

    	$(document).ready(function() {
    		$("#goodCodeIds").quickTip("setjson",{},function(){
    		});
    	});
		var rec_num = parseInt($("#rec_num").val());

        var newTr = addTable.insertRow();
        var newTd0 = newTr.insertCell();
        var newTd1 = newTr.insertCell();
        newTd0.innerHTML= '<table>'+
                    		'<tr>'+
                    		    '<td></td>'+
                    			'<td>'+
                    				'<select name="category" class="form-control" style="width:190px;">'+
                    			      '@foreach($allInfo[0] as $categoryInfo)'+
                    			      '<option value="{{$categoryInfo->category_id}}">{{$categoryInfo->category_name}}</option>'+
									  '@endforeach'+
                                   ' </select>'+
                               ' </td>'+
                                '<td>'+
                                    '@lang('messages.good_code')'+
                               ' </td>'+
                               ' <td><input type="hidden" id="goodsId_'+rec_num+'" name="goodsId_'+rec_num+'" value=""/>'+
                               '<input type="text"  id="goodsCode_' + rec_num+ '"  name=""  class="suggestion form-control" style="width:236px;">'+
                                '</td>'+
                                '<td>'+
                                   ' @lang('messages.good_name')'+
                               ' </td>'+
                                '<td>'+
                               ' <input type="hidden" id ="goodsCode_' + rec_num+ '"  name="SetGoodsMaster[goods_id' + setgood+ ']" value="">'+
                                '<input type="text" id="goodsName_' + rec_num+ '" class="form-control"  readonly="true" style="background:#FFFFFF">'+
                               ' </td>'+
                               ' <td>'+
                                   ' <button type="button" id="delete_goods" class="button_delete button_normal" onclick="remove(this)"value="削除">削除</button> '+
                                '</td>'+
                    	 	'</tr>'+
                    	 '</table>';
        newTd1.innerHTML = '';
		$("#rec_num").val(rec_num+1);
     }
</script>
<div class="system_tab_line"></div>
<tr>
	<td style="width: 10%">セット品</td>
	<td style="width: 20%"></td>
</tr>
<div id="set_container">
	<form id="setForm" class="pure-form pure-form-stacked" method="POST">
		<fieldset>
			<table id="addTable">
				<tr>
					<td colspan="2">
						<table class="">
						<tr>
        					<td>セット名称</td>
        					<td >
        					<?php if(empty($setMasterInfo->set_id)):?>
        					<input type='text' name="set_name" class="pure-form" id="set_name"/>
        					<?php else:?>
        					<input type='text' name="set_name" class="pure-form" value="<?php echo $setMasterInfo->set_name; ?>"  id="set_name"/>
        					<?php endif;?>

        					</td>
				        </tr>
							<tr>
								<td>@lang('messages.saleExp') &nbsp;</td>
								<td align="center">
									<div class="row">
										<div class="col-sm-6">
											<input type='text' name="start_date"
												class="pure-form" value="<?php echo $setMasterInfo->start_date; ?>" id='start_date' />
										</div>
									</div>
								</td>
								<td> &nbsp; ～  &nbsp;</td>
								<td align="center">
									<div class="row">
										<div class="col-sm-6">
											<input type='text' name="end_date"
												class="pure-form" id='end_date' value="<?php echo  $setMasterInfo->end_date; ?>"/>
										</div>
									</div>
								</td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
						</table>
						</td>
				</tr>
				<tr>
					<td>@lang('messages.sale_goods')</td>
					<td ><button type="button"
										class="button_add_sale pure-button pure-button-primary"
										value="商品追加" onclick="addRow();">商品追加</button></td>
				</tr>
				<tr>
					<td>
						<table id="tblData">
						<?php $i=0;?>
						<?php foreach ($setGoods as $goods):?>
							<tr id="tRow0">
								<td></td>
								<td><select name="category" class="form-control" style="width: 190px;">
									@foreach($allInfo[0] as $categoryInfo)
										<option value="{{$categoryInfo->category_id}}">{{$categoryInfo->category_name}}</option>
									@endforeach
								</select></td>
								<td> @lang('messages.good_code')</td>
								<td>
								<input type="hidden" id="goodsId" name="goodsId_{{$i}}"
									class="suggestion form-control" style="width: 236px;" value="{{$goods->goods_id}}"/>
								<input type="text" id="goodsCode_{{$i}}"
									class="suggestion form-control" style="width: 236px;" value="{{$goods->goods_code}}"/></td>
								<td> @lang('messages.good_name') </td>
								<td> <input type="text"
									id="goodsName_{{$i}}" name="" class="form-control" value="{{$goods->goods_name}}"
									readonly="true" style="background: #FFFFFF"></td>
								<td>

								</td>
							</tr>
							<?php $i++;?>
							<?php endforeach;?>
						</table>
					</td>
					<td align="left"></td>
				</tr>
				<!--<div style=" margin-right:610px;margin-top:68px; float:right;">-->
			</table>
			<div id="button_box_bottom" style="">
			<?php if(empty($setMasterInfo->set_id)):?>
			<button id="button_save_sale" type="button"
					onclick="onSubmitSave('create');"
					class="pure-button pure-button-primary button_normal">@lang('messages.save')</button>
			<?php else:?>
			<button id="button_save_sale" type="button"
					onclick="onSubmitSave('update');"
					class="pure-button pure-button-primary button_normal">@lang('messages.save')</button>
			<?php endif;?>

				<button id="button_cancel" type="button"
					onclick="location.href='home'"
					class="pure-button pure-button-primary button_normal">@lang('messages.cancel')</button>
				 <input type="button" value="戻る"
					class="pure-button pure-button-primary button_normal"
					onclick="onSubmitGo()" />
			</div>
		</fieldset>
		<input type="hidden" name="_token" value="{{csrf_token()}}">
		<input type="hidden" name="rec_num" id="rec_num" value="<?php echo count($setGoods)?>"/>
		<input type="hidden" name="set_id" value = "<?php echo $setMasterInfo->set_id; ?>" />
	</form>
</div>
@endsection
